package com.jdbctemplate.demo.service.impl;

import com.jdbctemplate.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * @ClassName UserServiceImpl
 * @description: TODO
 * @author: 朱同学
 * @Date 2021/4/10 21:48
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public Integer save(String userName, Integer id) {

        return jdbcTemplate.update("insert into user (id,user_name) values (?,?)", id, userName);
    }

    @Override
    public Integer delByName(String userName) {


        return jdbcTemplate.update("delete from user where user_name = ?", userName);
    }

    @Override
    public Integer getAllUsers() {
        return jdbcTemplate.queryForObject("select count(1) from user", Integer.class);
    }

    @Override
    public Integer delAllUser() {
        return jdbcTemplate.update("delete from user");
    }
}
